package com.lovo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.system.dto.PageDto;
import com.lovo.system.dto.StockDto;
import com.lovo.system.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    IStockService stockService;

    @RequestMapping("/info")
    public IPage<StockDto> info(@RequestBody PageDto<StockDto> pageDto){
        return stockService.info(pageDto.getCurPage(),pageDto.getPageSize(),
                pageDto.getStartNumber(),pageDto.getEndNumber(),pageDto.getData().getStockName(),
                pageDto.getData().getStockType(),pageDto.getPriceStatus());
    }

    @RequestMapping("/add")
    public void addStock(@RequestBody StockDto stockDto){
        if (stockService.selectRepeat(stockDto)==1){
            stockService.insertStock(stockDto);
        }
    }

    @RequestMapping("/selectByCode")
    public StockDto selectByCode(String code){
        return stockService.selectByCode(code);
    }

    @RequestMapping("/queryOne")
    public StockDto queryOne(int id){
        return stockService.queryOneById(id);
    }

    @RequestMapping("/updatePrice")
    public String updatePrice(@RequestBody StockDto stockDto){
        return stockService.updatePrice(stockDto);
    }

    @RequestMapping("/delete")
    public void deleteStock(int id){
        stockService.deleteStock(id);
    }

    @RequestMapping("/changeNumber")
    public void changeNumber(String name,int number){
        stockService.changeNumber(name,number);
    }

}
